package com.yanqu.road.server.cmd.activity.advertisement;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.AdvertisementProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.advertisement.AdvertisementActivityModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ADVERTISEMENT_ACTIVITY_START_WATCH,desc = "广告活动开始观看")
public class AdvertisementStartWatchingCmd extends AbstractCommand {

    private int activityId;
    private int systemId;
    private long startTime;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AdvertisementProto.WatchAdvertisementStartReqMsg watchAdvertisementStartReqMsg = AdvertisementProto.WatchAdvertisementStartReqMsg.parseFrom(packet.getBytes());
        activityId = watchAdvertisementStartReqMsg.getActivityId();
        systemId = watchAdvertisementStartReqMsg.getId();
        startTime = watchAdvertisementStartReqMsg.getStartTime();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(AdvertisementActivityModule.class).watchAdStart(activityId,systemId,startTime);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            AdvertisementProto.WatchAdvertisementStartRespMsg.Builder builder = AdvertisementProto.WatchAdvertisementStartRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_ADVERTISEMENT_ACTIVITY_START_WATCH,builder);
        }
    }
}
